var path = "http://24.43.105.10:18081";
//var path = "http://172.16.11.150";
//var fileResult = "";
var sessionStorage = window.sessionStorage;
//导入接口
function upload() {
    var fileObj = document.getElementById("btn_file").files[0]
    var sendData = new FormData();
    sendData.append('file', fileObj);
    $.ajax({
        type: 'post',
        url: path+"/epplatform/file/calculate/upload",
        async: false,
        data: sendData,
        processData: false,
        contentType: false,
        success: function (data) {
            if (data.success) {
                //fileResult = data.data;
                sessionStorage.setItem("fileResult",data.data);
            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
}

//计算接口
function calculate(uri) {

    $.ajax({
        type: 'post',
        url: path+'/epplatform/file/calculate/'+uri,
        async: false,
        contentType:'application/x-www-form-urlencoded',
        //data:'fileName=20191219160525876.xlsx',
        data:'fileName='+sessionStorage.getItem("fileResult"),
        success: function (data) {
            if (data.success) {
                sessionStorage.removeItem("fileResult");
                setCalculate(data.data);
            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
}

//获取区域名称和对应的id
function getArea() {
    var result = [];
    $.ajax({
        type: 'get',
        url: path + "/epplatform/areaStateTrack/getAreaIdAndName",
        async: false,
        // processData: false,
        // contentType:false,
        success: function (data) {
            if (data.success) {
                var a = "";
                a = data.data;
                for (var i = 0; i < a.length; i++) {
                    var map = {};
                    if (a[i].areaName != undefined) {
                        map.label = a[i].areaName;
                        map.value = a[i].id;
                        result.push(map);
                    }

                }

            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
    //console.log("--getArea---",result);
    return result;
}
//获取场站接口
function getStation(id) {
    var result = [];
    $.ajax({
        type: 'get',
        url: path + "/epplatform/areaStateTrack/getStationIdAndNameInArea",
        async: false,
        data: {
            areaId: id
        },
        // processData: false,
        // contentType:false,
        success: function (data) {

            if (data.success) {
                var a = "";
                a = data.data;
                for (var i = 0; i < a.length; i++) {
                    var map = {};
                    if (a[i].stationName != undefined) {
                        map.label = a[i].stationName;
                        map.value = a[i].id;
                        result.push(map);
                    }

                }

            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
    //console.log("--getArea---",result);
    return result;
}
//获取机组接口
function getFan(id) {
    var result = [];
    $.ajax({
        type: 'get',
        url: path + "/epplatform/areaStateTrack/getFanIdAndNameInStation",
        async: false,
        data: {
            areaId: id
        },
        // processData: false,
        // contentType:false,
        success: function (data) {

            if (data.success) {
                var a = "";
                a = data.data;
                for (var i = 0; i < a.length; i++) {
                    var map = {};
                    if (a[i].fanName != undefined) {
                        map.label = a[i].fanName;
                        map.value = a[i].id;
                        result.push(map);
                    }

                }

            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
    //console.log("--getArea---",result);
    return result;
}

//机组风速功率信息
function unitPowerInfo(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/powerCurve/unitPowerInfoList",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({

            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime

            // "unitId": "610",
            // "startTime": "1556873668000",
            // "endTime": "1575363268000"


        }),
        success: function (data) {

            if (data.success) {

                setPowerInfo(data.data)

            }

        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });
}

//机组功率曲线评价信息
function curveEvaluateInfo(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/powerCurve/curveEvaluateInfo",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({

            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime

            //   "stationId": "610",
            //   "startTime": "1556873668000",
            //   "endTime": "1575363268000"

        }),
        success: function (data) {

            if (data.success) {
                setCurveEvaluateInfo(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}

//机组功率曲线信息
function unitPowerCurveInfo(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/powerCurve/unitPowerCurveInfo",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime
            // "stationId": "610",
            // "startTime": "1556873668000",
            // "endTime": "1575363268000"


        }),
        success: function (data) {

            if (data.success) {
                setUnitPowerCurve(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}


//偏差角度热力图
function angleThermodynamicChart(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/yawError/angleThermodynamicChart",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime
            // "stationId": "610",
            // "startTime": "1556873668000",
            // "endTime": "1575363268000"


        }),
        success: function (data) {

            if (data.success) {
                setHeartChart(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}
//偏差角度仪表图3~7.5m/s偏差
function angleMeterChartForOne(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/yawError/angleMeterChartForOne",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime
            // "stationId": "610",
            // "startTime": "1556873668000",
            // "endTime": "1575363268000"


        }),
        success: function (data) {

            if (data.success) {
                setAngleChartOne(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}
//偏差角度仪表图7.5~11.2m/s偏差
function angleMeterChartForTwo(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/yawError/angleMeterChartForTwo",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime
            // "stationId": "610",
            // "startTime": "1556873668000",
            // "endTime": "1575363268000"


        }),
        success: function (data) {

            if (data.success) {
                setAngleChartTwo(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}


//偏差角度列表数据
function angleListTable(unitId, startTime, endTime) {

    $.ajax({
        type: 'post',
        url: path + "/epplatform/v1/yawError/angleList",
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            "unitId": unitId,
            "startTime": startTime,
            "endTime": endTime
            // "unitId":"650" ,
            // "startTime":"1556873668000",
            // "endTime":"1575363268000"

        }),
        success: function (data) {

            if (data.success) {
                setAngleListTable(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}

//偏差角度角度折线图
function angleList(area,station,unitId, startTime, endTime) {
    $.ajax({
        type: 'post',
        url: path+'/epplatform/v1/yawError/getUnitLine',
        async: true,
        dataType: "json",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
            // "areaId":"5" ,
            // "stationId":"17" ,
            // "unitId":"1162" ,
            // "startTime":"",
            // "endTime":""
            "areaId":area ,
            "stationId":station ,
            "unitId":unitId ,
            "startTime":startTime,
            "endTime":endTime
        }),
        success: function (data) {

            if (data.success) {
                setAngleList(data.data)
            }
        },
        error: function (xhr) {
            alert("警告：" + xhr.status + " 网络异常请联系管理员");
        }
    });

}
